{
LANG : PASCAL
PROB : preface
}
program PREFACE;
const
  fi = 'preface.in';
  fo = 'preface.out';
type
  num = string[4];
const
  Rletter : array[1..7] of char = ('I', 'V', 'X', 'L', 'C', 'D', 'M');
  donvi : array[0..9] of num =
  ('', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX');
  chuc : array[0..9] of num =
  ('', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC');
  tram : array[0..9] of num =
  ('', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM');
  nghin : array[0..3] of num =
  ('', 'M', 'MM', 'MMM');
var
  v : array['A'..'Z'] of longint;
  m : longint;

function getlast(var k : longint) : byte;
begin
  getlast := k mod 10;
  k := k div 10;
end;

procedure process;
var
  i, j, temp : longint;
  ng, tr, ch, dv : integer;
  s : string;
begin
  fillchar(v, sizeof(v), 0);
  for i := 1 to m do
  begin
    temp := i;
    dv := getlast(temp);
    ch := getlast(temp);
    tr := getlast(temp);
    ng := getlast(temp);
    s := nghin[ng] + tram[tr] + chuc[ch] + donvi[dv];
    for j := 1 to length(s) do inc(v[s[j]]);
  end;
end;

procedure out;
var
  i : integer;
  c : char;
begin
  for i := 1 to 7 do
  begin
    c := Rletter[i];
    if v[c] > 0 then writeln(c, ' ', v[c]);
  end;
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  read(m);
  process;
  out;
  close(output);
  close(input);
end.
